<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SkidPad4DOF</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] },
  TeX: { equationNumbers: { autoNumber: 'all' } }
});
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
body > * {
  max-width: 1000px;
}
body {
  font-family: "Roboto Condensed", sans-serif;
  padding-left: 7.5em;
  padding-right: 7.5em;
}
pre, code {
  max-width: 60em;
  font-family: monospace;
}
pre.oct-code {
  border: 1px solid Grey;
  padding: 5px;
}
pre.oct-code-output {
  margin-left: 2em;
}
span.comment {
  color: ForestGreen;
}
span.keyword {
  color: Blue;
}
span.string {
  color: DarkOrchid;
}
footer {
  margin-top: 2em;
  font-size: 80%;
}
a, a:visited {
  color: Blue;
}
h2 {
  font-family: "Roboto Condensed", serif;
  margin-top: 1.5em;
}
h2 a, h2 a:visited {
  color: Black;
}
</style>
</head>
<body>
<p><b>Defining parameters</b></p><pre class="oct-code"><span class="comment">% Choosing tire</span>
TireModel = TirePacejka();
<span class="comment">% Choosing vehicle</span>
System = VehicleSimpleNonlinear4DOF();
<span class="comment">% Defining vehicle parameters</span>
System.mF0 = 700;
System.mR0 = 600;
System.lT = 3.5;
System.nF = 1;
System.nR = 1;
System.wT = 2;
System.muy = 1;
System.deltaf = 10*pi/180;
System.FXFRONTLEFT = 0;
System.FXFRONTRIGHT = 0;
System.FXREARLEFT = @VelControl4DOF;
System.FXREARRIGHT = @VelControl4DOF;
System.K = 50000000;                <span class="comment">% Torcional stiffness</span>
System.C = 5000000;

System.H = 0.6;                     <span class="comment">% CG height [m]</span>
System.L = 0.6;                     <span class="comment">% track [m]</span>
System.IXX = 12000;
System.IYY = 65000;
System.IZZ = 65000;
System.IXY = 1000;
System.IXZ = 1000;
System.IYZ = 1000;

System.tire = TireModel;

<span class="comment">% Choosing simulation</span>
T = 20;                             <span class="comment">% Total simulation time [s]</span>
resol = 200;                        <span class="comment">% Resolution</span>
TSPAN = 0:T/resol:T;                <span class="comment">% Time span [s]</span>
simulator = Simulator(System, TSPAN);

simulator.V0 = 8;</pre><p><b>Run simulation</b></p><pre class="oct-code">simulator.Simulate();</pre><p><b>Results</b></p><pre class="oct-code"><span class="comment">% Retrieving states</span>
XT = simulator.XT;
YT = simulator.YT;
PSI = simulator.PSI;
THETA = simulator.THETA;
VEL = simulator.VEL;
ALPHAT = simulator.ALPHAT;
dPSI = simulator.dPSI;
dTHETA = simulator.dTHETA;

<span class="comment">% Retrieving data from vehicle</span>
m = System.mT;
a = System.a;
b = System.b;
K = 50000000;                       <span class="comment">% Torcional stiffness of the sprung mass</span>
CC = 5000000;
h = 0.6;                            <span class="comment">% CG height [m]</span>
l = 0.6;                            <span class="comment">% track [m]</span>
g = 9.81;

FzRight = (m*g*l/2 + K*THETA + CC*dTHETA)/l;
FzLeft = m*g - FzRight;

FzFrontRight = FzRight*b/(a+b);
FzFrontLeft = FzLeft*b/(a+b);
FzRearRight = FzRight*a/(a+b);
FzRearLeft = FzLeft*a/(a+b);


f1 = figure(1);
hold on ; grid on ; box on
plot(TSPAN,XT)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Distance in the x direction [m]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig1.svg" alt="../illustrations/plot/SkidPad4DOFFig1.svg"><pre class="oct-code">f2 = figure(2);
hold on ; grid on ; box on
plot(TSPAN,YT)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Distance in the y direction [m]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig2.svg" alt="../illustrations/plot/SkidPad4DOFFig2.svg"><pre class="oct-code">f3 = figure(3);
hold on ; grid on ; box on
plot(TSPAN,PSI)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Yaw angle [rad]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig3.svg" alt="../illustrations/plot/SkidPad4DOFFig3.svg"><pre class="oct-code">f4 = figure(4);
hold on ; grid on ; box on
plot(TSPAN,THETA)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Roll angle [rad]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig4.svg" alt="../illustrations/plot/SkidPad4DOFFig4.svg"><pre class="oct-code">f5 = figure(5);
hold on ; grid on ; box on
plot(TSPAN,VEL)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Velocity [m/s]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig5.svg" alt="../illustrations/plot/SkidPad4DOFFig5.svg"><pre class="oct-code">f6 = figure(6);
hold on ; grid on ; box on
plot(TSPAN,ALPHAT)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Vehicle slip angle [rad/s]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig6.svg" alt="../illustrations/plot/SkidPad4DOFFig6.svg"><pre class="oct-code">f7 = figure(7);
hold on ; grid on ; box on
plot(TSPAN,dPSI)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Yaw rate [rad/s]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig7.svg" alt="../illustrations/plot/SkidPad4DOFFig7.svg"><pre class="oct-code">f8 = figure(8);
hold on ; grid on ; box on
plot(TSPAN,dTHETA)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Roll rate [rad/s]'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig8.svg" alt="../illustrations/plot/SkidPad4DOFFig8.svg"><pre class="oct-code">f9 = figure(9);
hold on ; grid on ; box on
plot(TSPAN,FzFrontRight,<span class="string">'r'</span>)
plot(TSPAN,FzRearRight,<span class="string">'g'</span>)
plot(TSPAN,FzFrontLeft,<span class="string">'b'</span>)
plot(TSPAN,FzRearLeft,<span class="string">'m'</span>)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Vertical force [N]'</span>)
legend(<span class="string">'Front Right'</span>,<span class="string">'Rear Right'</span>,<span class="string">'Front Left'</span>,<span class="string">'Rear Left'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig9.svg" alt="../illustrations/plot/SkidPad4DOFFig9.svg"><pre class="oct-code">f10 = figure(10);
hold on ; grid on ; box on
plot(TSPAN,FzFrontRight + FzFrontLeft,<span class="string">'r'</span>)
plot(TSPAN,FzRearRight + FzRearLeft,<span class="string">'g'</span>)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Vertical force [N]'</span>)
legend(<span class="string">'Front axle'</span>,<span class="string">'Rear axle'</span>)</pre><img width="500" src="../illustrations/plot/SkidPad4DOFFig10.svg" alt="../illustrations/plot/SkidPad4DOFFig10.svg"><p>mF0</p><pre class="oct-code">disp(num2str(System.mF0))</pre><p>mR0</p><pre class="oct-code">disp(num2str(System.mR0))</pre><p>Frame and animation</p><pre class="oct-code">g = Graphics(simulator);
g.TractorColor = <span class="string">'r'</span>;

g.Frame();</pre><img width="800" src="../illustrations/frame/SkidPad4DOFFrame.svg" alt="../illustrations/frame/SkidPad4DOFFrame.svg"><pre class="oct-code">angulo = 0:0.01:2*pi;

[R,XC,YC] = circfit(XT(40:end),YT(40:end));

XX = XC + R*cos(angulo);
YY = YC + R*sin(angulo);

hold on
plot(XX,YY,<span class="string">'k'</span>)

g.Animation();</pre><img src="../illustrations/animation/SkidPad4DOFAnimation.gif" alt="../illustrations/animation/SkidPad4DOFAnimation.gif"><p>Maneuver radius</p><pre class="oct-code">disp(num2str(R))</pre>
<footer><hr><a href="http://www.octave.org">Published with GNU Octave 4.2.1</a></footer>
<!--
##### SOURCE BEGIN #####
%%
% *Defining parameters*

% Choosing tire
TireModel = TirePacejka();
% Choosing vehicle
System = VehicleSimpleNonlinear4DOF();
% Defining vehicle parameters
System.mF0 = 700;
System.mR0 = 600;
System.lT = 3.5;
System.nF = 1;
System.nR = 1;
System.wT = 2;
System.muy = 1;
System.deltaf = 10*pi/180;
System.FXFRONTLEFT = 0;
System.FXFRONTRIGHT = 0;
System.FXREARLEFT = @VelControl4DOF;
System.FXREARRIGHT = @VelControl4DOF;
System.K = 50000000;                % Torcional stiffness
System.C = 5000000;

System.H = 0.6;                     % CG height [m]
System.L = 0.6;                     % track [m]
System.IXX = 12000;
System.IYY = 65000;
System.IZZ = 65000;
System.IXY = 1000;
System.IXZ = 1000;
System.IYZ = 1000;

System.tire = TireModel;

% Choosing simulation
T = 20;                             % Total simulation time [s]
resol = 200;                        % Resolution
TSPAN = 0:T/resol:T;                % Time span [s]
simulator = Simulator(System, TSPAN);

simulator.V0 = 8;

%%
% *Run simulation*
%

simulator.Simulate();

%%
% *Results*
%

% Retrieving states
XT = simulator.XT;
YT = simulator.YT;
PSI = simulator.PSI;
THETA = simulator.THETA;
VEL = simulator.VEL;
ALPHAT = simulator.ALPHAT;
dPSI = simulator.dPSI;
dTHETA = simulator.dTHETA;

% Retrieving data from vehicle
m = System.mT;
a = System.a;
b = System.b;
K = 50000000;                       % Torcional stiffness of the sprung mass
CC = 5000000;
h = 0.6;                            % CG height [m]
l = 0.6;                            % track [m]
g = 9.81;

FzRight = (m*g*l/2 + K*THETA + CC*dTHETA)/l;
FzLeft = m*g - FzRight;

FzFrontRight = FzRight*b/(a+b);
FzFrontLeft = FzLeft*b/(a+b);
FzRearRight = FzRight*a/(a+b);
FzRearLeft = FzLeft*a/(a+b);


f1 = figure(1);
hold on ; grid on ; box on
plot(TSPAN,XT)
xlabel('time [s]')
ylabel('Distance in the x direction [m]')

%%
% <<../illustrations/plot/SkidPad4DOFFig1.svg>>

f2 = figure(2);
hold on ; grid on ; box on
plot(TSPAN,YT)
xlabel('time [s]')
ylabel('Distance in the y direction [m]')

%%
% <<../illustrations/plot/SkidPad4DOFFig2.svg>>

f3 = figure(3);
hold on ; grid on ; box on
plot(TSPAN,PSI)
xlabel('time [s]')
ylabel('Yaw angle [rad]')

%%
% <<../illustrations/plot/SkidPad4DOFFig3.svg>>

f4 = figure(4);
hold on ; grid on ; box on
plot(TSPAN,THETA)
xlabel('time [s]')
ylabel('Roll angle [rad]')

%%
% <<../illustrations/plot/SkidPad4DOFFig4.svg>>

f5 = figure(5);
hold on ; grid on ; box on
plot(TSPAN,VEL)
xlabel('time [s]')
ylabel('Velocity [m/s]')

%%
% <<../illustrations/plot/SkidPad4DOFFig5.svg>>

f6 = figure(6);
hold on ; grid on ; box on
plot(TSPAN,ALPHAT)
xlabel('time [s]')
ylabel('Vehicle slip angle [rad/s]')

%%
% <<../illustrations/plot/SkidPad4DOFFig6.svg>>

f7 = figure(7);
hold on ; grid on ; box on
plot(TSPAN,dPSI)
xlabel('time [s]')
ylabel('Yaw rate [rad/s]')

%%
% <<../illustrations/plot/SkidPad4DOFFig7.svg>>

f8 = figure(8);
hold on ; grid on ; box on
plot(TSPAN,dTHETA)
xlabel('time [s]')
ylabel('Roll rate [rad/s]')

%%
% <<../illustrations/plot/SkidPad4DOFFig8.svg>>

f9 = figure(9);
hold on ; grid on ; box on
plot(TSPAN,FzFrontRight,'r')
plot(TSPAN,FzRearRight,'g')
plot(TSPAN,FzFrontLeft,'b')
plot(TSPAN,FzRearLeft,'m')
xlabel('time [s]')
ylabel('Vertical force [N]')
legend('Front Right','Rear Right','Front Left','Rear Left')

%%
% <<../illustrations/plot/SkidPad4DOFFig9.svg>>

f10 = figure(10);
hold on ; grid on ; box on
plot(TSPAN,FzFrontRight + FzFrontLeft,'r')
plot(TSPAN,FzRearRight + FzRearLeft,'g')
xlabel('time [s]')
ylabel('Vertical force [N]')
legend('Front axle','Rear axle')

%%
% <<../illustrations/plot/SkidPad4DOFFig10.svg>>

%%
% mF0

disp(num2str(System.mF0))

%%
% mR0

disp(num2str(System.mR0))


%%
% Frame and animation

g = Graphics(simulator);
g.TractorColor = 'r';

g.Frame();

%%
% <<../illustrations/frame/SkidPad4DOFFrame.svg>>

%%
%

angulo = 0:0.01:2*pi;

[R,XC,YC] = circfit(XT(40:end),YT(40:end));

XX = XC + R*cos(angulo);
YY = YC + R*sin(angulo);

hold on
plot(XX,YY,'k')

g.Animation();

%%
% <<../illustrations/animation/SkidPad4DOFAnimation.gif>>

%%
% Maneuver radius

disp(num2str(R))
##### SOURCE END #####
-->
</body>
</html>
